package marksys.free.com.marksys.di;

import android.content.Context;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import marksys.free.com.marksys.App;
import marksys.free.com.marksys.nettool.FaceApiService;
import marksys.free.com.marksys.nettool.MyApi;
import marksys.free.com.marksys.nettool.retrofit.FaceRetrofitUtils;
import marksys.free.com.marksys.nettool.retrofit.RetrofitUtils;
import okhttp3.OkHttpClient;

/**
 * 基础依赖提供
 *
 * @author yawei
 * @data on 2018/7/10 下午1:24
 * @email zyawei@live.com
 */
@Module()
public class AppModule {


    @Singleton
    @Provides
    Context provideApplication(App app) {
        return app;
    }

    /*@Singleton
    @Provides
    AppExecutors appExecutors() {
        return new AppExecutors();
    }
*/

    @Singleton
    @Provides
    OkHttpClient provideOkHttp(/*TokenManager tokenManager*/) {
        return new OkHttpClient.Builder()
                .connectTimeout(8000, TimeUnit.MILLISECONDS)
                .readTimeout(8000, TimeUnit.MILLISECONDS)
                .writeTimeout(8000, TimeUnit.MILLISECONDS)
                /*.addNetworkInterceptor(chain -> {
                    Request original = chain.request();
                    Request.Builder newBuilder = original.newBuilder();
                    Data value = tokenManager.getToken();
                    if (!TextUtils.isEmpty(value)) {
                        newBuilder.addHeader("Token", value);
                    }
                    Timber.v("OKHttp Request URL= [%s]", original.url());
                    if (ObjectUtils.equals("POST", original.method())) {
                        RequestBody bodyUnSign = original.body();
                        assert bodyUnSign != null;
                        *//*todo AES*//*
                        newBuilder.post(bodyUnSign);
                    } else {
                        newBuilder.get();
                    }
                    Request request = newBuilder.build();
                    return chain.proceed(request);
                })
*/
                .build();
    }

    @Singleton
    @Provides
    MyApi.ApiService provideApiService() {
        return RetrofitUtils.getInstance().apiService;
    }

    @Singleton
    @Provides
    FaceApiService provideApiServiceForFace() {
        return FaceRetrofitUtils.getInstance().apiService;
    }
}
